home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / disk / misc / CltdUtils.lha / ReadErr.asm < prev    next >
Encoding:
Assembly Source File  |  1990-05-24  |  19.1 KB  |  752 lines

  1. *****************************************************************************
  2. *  Program:  ReadErr.asm V1.0 - ©1990 by Jeff Lavin
  3. *  Descrip:  Report read errors.
  4. *    Usage:  1> ReadErr <unit> [loBlk] [hiBlk]
  5. *   Author: Jeff Lavin
  6. *  History: 05/24/90 V1.00 Created
  7. ******************************* tear here ***********************************
  8.  
  9. SYS    macro        ;General purpose macro
  10.     jsr    _LVO\1(a6)    ;Call the function
  11.     endm
  12.  
  13. STRUCTURE    macro
  14. \1    set    0
  15. SOFFSET    set    \2
  16.     endm
  17.  
  18. APTR    macro
  19. \1    equ    SOFFSET
  20. SOFFSET    set    SOFFSET+4
  21.     endm
  22.  
  23. BPTR    macro
  24. \1    equ    SOFFSET
  25. SOFFSET    set    SOFFSET+4
  26.     endm
  27.  
  28. LONG    macro
  29. \1    equ    SOFFSET
  30. SOFFSET    set    SOFFSET+4
  31.     endm
  32.  
  33. WORD    macro
  34. \1    equ    SOFFSET
  35. SOFFSET    set    SOFFSET+2
  36.     endm
  37.  
  38. BYTE    macro
  39. \1    equ    SOFFSET
  40. SOFFSET    set    SOFFSET+1
  41.     endm
  42.  
  43. STRUCT    macro
  44. \1    equ    SOFFSET
  45. SOFFSET    set    SOFFSET+\2
  46.     endm
  47.  
  48. LABEL    macro
  49. \1    equ    SOFFSET
  50.     endm
  51.  
  52. SysBase    equ    4    ;Exec library base pointer
  53.  
  54. cd_BoardAddr    equ    $20    ;ConfigDev Structure
  55.  
  56. * AutoConfig Board Equates
  57.  
  58. MANF_CLTD    equ    1004    ;Manufacturer number
  59. PROD_12    equ    12    ;Current product rev number
  60. PROD_14    equ    14    ;Earlier product rev number
  61. CLTD_HOST    equ    7    ;SCSI Unit number of Host Controller
  62.  
  63. * Class 00 SCSI Command Structure - (General form, specific commands vary)
  64.  
  65. sc_cmd    equ    0    ;Command OpCode
  66. sc_adrH    equ    1    ;Logical Block Address (MSB)
  67. sc_adrM    equ    2    ;Logical Block Address
  68. sc_adrL    equ    3    ;Logical Block Address (LSB)
  69. sc_count    equ    4    ;Block Count
  70. sc_reserv    equ    5    ;Reserved
  71.  
  72. * NCR5380 SCSI Host Controller registers  - Offset = ([reg] * 2) + 1
  73. * ------------------------------------------------------------------
  74. ncr_data    equ    $01    ;(0) Current SCSI Data           (R)
  75.             ;    Output Data                 (W)
  76. ncr_icmd    equ    $03    ;(1) Initiator Command           (R/W)
  77. ncr_mode    equ    $05    ;(2) Mode                        (R/W)
  78. ncr_tcmd    equ    $07    ;(3) Target Command              (R/W)
  79. ncr_bstat    equ    $09    ;(4) Current SCSI Bus Status     (R)
  80.             ;    Select Enable               (W)
  81. ncr_stat    equ    $0B    ;(5) Bus and Status              (R)
  82.             ;    Start DMA Send              (W)
  83. ncr_input    equ    $0D    ;(6) Input Data                  (R)
  84.             ;    Start DMA Target Receive    (W)
  85. ncr_reset    equ    $0F    ;(7) Reset Parity/Interrupts   (R)
  86.             ;    Start DMA Initiator Receive (W)
  87. * SCSI Command OpCodes
  88.  
  89. READ    equ    $08
  90. TRANSLATE    equ    $0F
  91. READ_CAP    equ    $25
  92.  
  93. * Equates for Initiator Command Register (1)
  94.  
  95. ASS_NOT    equ    %00000000    ;Assert nothing, i.e., free data bus
  96. ASS_BUS    equ    %00000001    ;Assert Data Bus
  97. ASS_ATN    equ    %00000010    ;Assert Attention
  98. ASS_SEL    equ    %00000100    ;Assert Select
  99. ASS_BSY    equ    %00001000    ;Assert Busy
  100. ASS_ACK    equ    %00010000    ;Assert Acknowledge
  101. ASS_RST    equ    %10000000    ;Assert Reset
  102.  
  103. * Equates for Mode Register (2)
  104.  
  105. ARBITRATE    equ    0    ;Start arbitration
  106. MONITOR_BSY    equ    2    ;Generate busy lost interrupt
  107.  
  108. * SCSI Information Transfer Phases (for Target Command Register (3))
  109.  
  110. ASS_IO    equ    %00000001    ;Assert I/O
  111. ASS_CD    equ    %00000010    ;Assert C/D
  112. ASS_MSG    equ    %00000100    ;Assert MSG
  113.  
  114. PH_DOUT    equ    0    ;Data Out Phase
  115. PH_DIN    equ    ASS_IO    ;Data In Phase
  116. PH_CMD    equ    ASS_CD    ;Command Phase
  117. PH_STAT    equ    ASS_IO!ASS_CD    ;Status Phase
  118. PH_MOUT    equ    ASS_CD!ASS_MSG    ;Message Out Phase
  119. PH_MIN    equ    ASS_IO!ASS_CD!ASS_MSG ;Message In Phase
  120.  
  121. * Bit defs for Bus Status Register (4)
  122.  
  123. BCBS_DBP    equ    0    ;Data Bus Parity Status
  124. BCBS_SEL    equ    1    ;Select Phase Status
  125. BCBS_IO    equ    2    ;I/O Direction
  126. BCBS_CD    equ    3    ;Control / Data Status
  127. BCBS_MSG    equ    4    ;Message Phase
  128. BCBS_REQ    equ    5    ;Data Request Status
  129. BCBS_BSY    equ    6    ;SCSI Bus Busy Status
  130. BCBS_RST    equ    7    ;SCSI Bus Reset Status
  131.  
  132. * Equates for Status Register (5)
  133.  
  134. PHAS_MATCH    equ    3    ;Phase match bit def
  135. INT_REQ    equ    4    ;Interrupt request bit def
  136. DMA_REQ    equ    6    ;DMA request bit def
  137.  
  138. * Program variables
  139.  
  140.                STRUCTURE    WorkArea,0
  141.     APTR    InitialSP
  142.     APTR    DosBase
  143.     APTR    ExpBase
  144.     BPTR    stdout
  145.     WORD    Error    ;Offset into error msg table
  146.     WORD    Tries    ;# of tries to read data
  147.     BYTE    Device    ;SCSI Device number
  148.     BYTE    Unit    ;Adaptec Unit number
  149.     LONG    LoBlk    ;Start Block
  150.     LONG    HiBlk    ;Ending Block
  151.     BYTE    adrH    ;Logical Block Addr MSB
  152.     BYTE    adrM    ;Logical Block Addr
  153.     BYTE    adrL    ;Logical Block Addr LSB
  154.     BYTE    BlkCnt    ;Count for display
  155.     STRUCT    FmtArgs,4*4    ;Format args
  156.     STRUCT    SCSICmd,10    ;SCSI Command structure
  157.     STRUCT    OutBuf,300    ;Output buffer
  158.     STRUCT    ScsiData,2048    ;Read data buffer
  159.     LABEL    Work_Sizeof
  160.  
  161. _LVODisable    equ    -$78
  162. _LVOEnable    equ    -$7E
  163. _LVOSetSignal    equ    -$132
  164. _LVOCloseLibrary    equ    -$19E
  165. _LVORawDoFmt    equ    -$20A
  166. _LVOOpenLibrary    equ    -$228
  167.  
  168. _LVOWrite    equ    -$30
  169. _LVOOutput    equ    -$3C
  170.  
  171. _LVOFindConfigDev    equ    -$48
  172.  
  173.     errfile    'ram:assem.output'
  174.     exeobj
  175.     objfile    'ReadErr'
  176.  
  177. ReadErr    lea    DT(pc),a5
  178.     movea.l    a5,a1    ;Clear BSS section
  179.     move.w    #(Work_Sizeof/4)-1,d1
  180. 1$    clr.l    (a1)+
  181.     dbra    d1,1$
  182.  
  183.     move.l    d0,d2    ;Save cmd line
  184.     movea.l    a0,a2
  185.     move.l    sp,InitialSP(a5)
  186.  
  187.     movea.l    SysBase,a6
  188.     lea    DosName(pc),a1
  189.     moveq    #0,d0
  190.     SYS    OpenLibrary    ;Open dos.library
  191.     move.l    d0,DosBase(a5)
  192.     beq    Exit
  193.  
  194.     movea.l    d0,a6
  195.     SYS    Output
  196.     move.l    d0,stdout(a5)
  197.     beq    Cleanup
  198.  
  199.     lea    BannerStr(pc),a0
  200.     bsr    Puts
  201.  
  202.     move.l    d2,d0    ;Get cmd line
  203.     movea.l    a2,a0
  204.     lea    0(a0,d0.w),a1
  205. 2$    cmpi.b    #' ',-(a1)    ;Eat trailing garbage
  206.     dbhi    d0,2$
  207.     blt    Instruct    ;If no args, error
  208.     clr.b    1(a1)    ;Null terminate the string
  209.  
  210. 3$    move.b    (a0)+,d0    ;Get 1st arg
  211.     beq    Instruct    ;No args
  212.     cmpi.b    #' ',d0    ;Skip spaces
  213.     beq.s    3$
  214.     cmpi.b    #'?',d0    ;Instruct?
  215.     beq    Instruct    ;"Usage:..."
  216.     subi.b    #$30,d0    ;Convert to number
  217.     blt    Error1    ;Not a number
  218.     cmpi.b    #15,d0    ;Only Units 0 to 15 allowed
  219.     bgt    Error1    ;Out of range
  220.     move.b    d0,d1
  221.     andi.b    #%00000111,d0    ;Extract Device number & save
  222.     move.b    d0,Device(a5)
  223.     lsr.b    #3,d1    ;Extract Adaptec unit number
  224.     lsl.b    #5,d1    ; and move to proper bit pos.
  225.     move.b    d1,Unit(a5)    ;Save unit
  226.  
  227.     bsr    AscBin    ;Get 2nd arg
  228.     bpl.s    4$
  229.     moveq    #0,d0
  230. 4$    move.l    d0,LoBlk(a5)
  231.  
  232.     bsr    AscBin    ;Get 3rd arg
  233.     bpl.s    5$
  234.     moveq    #0,d0
  235. 5$    move.l    d0,HiBlk(a5)
  236.  
  237.     movea.l    SysBase,a6
  238.     lea    ExpName(pc),a1    ;Open expansion.library
  239.     moveq    #0,d0    ;Any version
  240.     SYS    OpenLibrary
  241.     move.l    d0,ExpBase(a5)
  242.     beq    Error2
  243.  
  244.     movea.l    d0,a6
  245.     suba.l    a0,a0
  246.     move.l    #1004,d3
  247.     moveq    #14,d2
  248.     move.l    d3,d0
  249.     move.l    d2,d1
  250.     SYS    FindConfigDev
  251.     tst.l    d0
  252.     bne.s    6$
  253.  
  254.     suba.l    a0,a0
  255.     move.l    d3,d0
  256.     moveq    #12,d2
  257.     move.l    d2,d1
  258.     SYS    FindConfigDev
  259.     tst.l    d0
  260.     beq    Error3
  261. 6$    movea.l    d0,a4    ;Ptr to ConfigDev structure
  262.     movea.l    cd_BoardAddr(a4),a4
  263.  
  264.     movea.l    a6,a1
  265.     movea.l    SysBase,a6
  266.     SYS    CloseLibrary
  267.     clr.l    ExpBase(a5)
  268.  
  269.     move.b    Device(a5),d1    ;Read capacity
  270.     bsr    GenCmd    ;Generate the SCSI command
  271.     beq    Error4    ;Bad return, exit
  272.  
  273.     lea    SCSICmd(a5),a3    ;Build our SCSI command
  274.     movea.l    a3,a0
  275.     move.b    #READ_CAP,(a0)+    ;Bit 0-4 = OpCode
  276.     move.b    Unit(a5),(a0)+    ;Bit 5-7 = Logical unit number
  277.     clr.b    (a0)+    ;Logical Block Addr MSB
  278.     clr.b    (a0)+    ;Logical Block Addr
  279.     clr.b    (a0)+    ;Logical Block Addr
  280.     clr.b    (a0)+    ;Logical Block Addr LSB
  281.     clr.b    (a0)+    ; Not used for this command
  282.     clr.b    (a0)+    ; Not used for this command
  283.     clr.b    (a0)+    ;Partial Media Indicator
  284.     clr.b    (a0)    ; Not used for this command
  285.     bsr    ScsiOutCmd    ;Send the SCSI command
  286.  
  287.     lea    ScsiData(a5),a2
  288.     bsr    GetData
  289.     bsr    SCSIStat
  290.     tst.b    d0
  291.     bne    Error5    ;Bad return, exit
  292.  
  293.     lea    FmtArgs(a5),a1
  294.     moveq    #0,d0
  295.     move.b    Device(a5),d0
  296.     move.w    d0,(a1)
  297.     move.b    Unit(a5),d0
  298.     lsr.b    #5,d0
  299.     move.w    d0,2(a1)
  300.     lea    ScsiData(a5),a0
  301.     move.l    (a0),4(a1)
  302.     lea    Capacity.fmt(pc),a0
  303.     bsr    Printf    ;"Capacity of Device %d, LUN %d = %ld Sectors"
  304.  
  305.     move.b    #99,BlkCnt(a5)
  306.  
  307. MainLoop    moveq    #8,d1
  308.     move.l    LoBlk(a5),d0
  309.     move.b    d0,adrL(a5)    ;Logical Block Addr (LSB)
  310.     lsr.l    d1,d0
  311.     move.b    d0,adrM(a5)    ;Logical Block Addr
  312.     lsr.l    d1,d0
  313.     move.b    d0,adrH(a5)    ;Logical Block Addr (MSB)
  314.  
  315.     clr.w    Tries(a5)
  316.  
  317. ReadBlock    move.b    Device(a5),d1
  318.     bsr    GenCmd    ;Generate the SCSI command
  319.     beq    Error4    ;Bad return, exit
  320.  
  321.     lea    SCSICmd(a5),a3    ;Build our SCSI command
  322.     movea.l    a3,a0
  323.     move.b    #READ,(a0)+    ;Bit 0-4 = OpCode
  324.     move.b    adrH(a5),d0    ;Bit 0-4 Logical Block Addr (MSB)
  325.     or.b    Unit(a5),d0    ;Bit 5-7 = Logical Unit Number
  326.     move.b    d0,(a0)+
  327.     move.b    adrM(a5),(a0)+    ;Logical Block Addr
  328.     move.b    adrL(a5),(a0)+    ;Logical Block Addr LSB
  329.     move.b    #1,(a0)+    ;Number of blocks
  330.     clr.b    (a0)    ; Not used for this command
  331.     bsr    ScsiOutCmd    ;Send the SCSI command
  332.  
  333.     lea    ScsiData(a5),a2
  334.     bsr    GetData
  335.     bsr    SCSIStat
  336.     tst.b    d0
  337.     beq.s    1$    ;No error, continue
  338.     addq.w    #1,Tries(a5)
  339.     cmpi.w    #20,Tries(a5)
  340.     bls.s    ReadBlock
  341.  
  342. 1$    tst.w    Tries(a5)    ;Any retries?
  343.     beq    3$    ;No, continue
  344.     lea    FmtArgs(a5),a1
  345.     move.l    LoBlk(a5),(a1)
  346.     move.l    Tries(a5),4(a1)
  347.     lea    ReadError.fmt(pc),a0    ;"Read Error at sector %ld, Retrys %d"
  348.     bsr    Printf
  349.  
  350.     move.b    Device(a5),d1
  351.     bsr    GenCmd    ;Generate the SCSI command
  352.     beq    Error4    ;Bad return, exit
  353.  
  354.     lea    SCSICmd(a5),a3    ;Build our SCSI command
  355.     movea.l    a3,a0
  356.     move.b    #TRANSLATE,(a0)+    ;Bit 0-4 = OpCode
  357.     move.b    adrH(a5),d0    ;Bit 0-4 Logical Block Addr (MSB)
  358.     or.b    Unit(a5),d0    ;Bit 5-7 = Logical Unit Number
  359.     move.b    d0,(a0)+
  360.     move.b    adrM(a5),(a0)+    ;Logical Block Addr
  361.     move.b    adrL(a5),(a0)+    ;Logical Block Addr LSB
  362.     clr.b    (a0)+    ; Not used for this command
  363.     clr.b    (a0)    ; Not used for this command
  364.     bsr    ScsiOutCmd    ;Send the SCSI command
  365.  
  366.     lea    ScsiData(a5),a2
  367.     bsr    GetData
  368.     bsr    SCSIStat
  369.     tst.b    d0
  370.     beq.s    2$    ;No error, continue
  371.  
  372.     lea    FmtArgs(a5),a1
  373.     lea    ScsiData(a5),a0
  374.     move.l    (a0),d0    ;Hi 3 bytes = Cylinder number
  375.     lsr.l    #8,d0
  376.     move.l    d0,(a1)
  377.     move.l    (a0),d0    ;Lo bytes = Head number
  378.     andi.w    #$FF,d0
  379.     move.w    d0,4(a1)
  380.     move.l    4(a0),6(a1)    ;Bytes from index
  381.     lea    CylHeadOffs.fmt(pc),a0    ;", Cyl %ld, Head %d, Offset %ld"
  382.     bsr    Printf
  383.     bra.s    4$
  384.  
  385. 2$    lea    NewLine(pc),a0
  386.     bsr    Puts
  387.     bra.s    4$
  388.  
  389. 3$    addq.b    #1,BlkCnt(a5)
  390.     cmpi.b    #100,BlkCnt(a5)
  391.     blt.s    4$
  392.     lea    FmtArgs(a5),a1
  393.     move.l    LoBlk(a5),(a1)
  394.     lea    Progress.fmt(pc),a0
  395.     bsr    Printf
  396.     sf    BlkCnt(a5)
  397.  
  398. 4$    bsr    CheckAbort
  399.     bne.s    Cleanup
  400.     addq.l    #1,LoBlk(a5)
  401.     move.l    LoBlk(a5),d0
  402.     cmp.l    HiBlk(a5),d0
  403.     bls    MainLoop
  404.     lea    Done.msg(pc),a0    ;Done
  405.     bsr    Puts
  406.     bra.s    Cleanup
  407.  
  408. Error5    addq.w    #4,Error(a5)    ;"Error reading capacity!!!"
  409. Error4    addq.w    #4,Error(a5)    ;"Drive not responding"
  410. Error3    addq.w    #4,Error(a5)    ;"NO CLtd Controller Found"
  411. Error2    addq.w    #4,Error(a5)    ;"Couldn't open expansion.library"
  412. Error1    addq.w    #4,Error(a5)    ;"Unit number must be 0>=15"
  413. Instruct    bsr    ReportError    ;"Usage: 1> ReadErr <unit>..."
  414. Cleanup    movea.l    SysBase,a6
  415.     move.l    ExpBase(a5),d0
  416.     beq.s    1$
  417.     movea.l    d0,a1
  418.     SYS    CloseLibrary
  419.  
  420. 1$    move.l    DosBase(a5),d0
  421.     beq.s    Exit
  422.     movea.l    d0,a1
  423.     SYS    CloseLibrary
  424.  
  425. Exit    move.l    InitialSP(a5),sp
  426.     moveq    #0,d0
  427.     rts
  428.  
  429. *************************************************************************
  430. * NAME:     AscBin()
  431. * FUNCTION: Convert an ASCII decimal number into a binary hex number.
  432. *           Scans past leading spaces.
  433. * INPUTS:   A0 = Ptr to ASCII number
  434. * RETURN:   D0 = Hex number if success, else -1.
  435. *           A0 = Points 1 char past last digit
  436. * SCRATCH:  None.
  437. *************************************************************************
  438.  
  439. AscBin    movem.l    d1/a1,-(sp)
  440.     moveq    #0,d1    ;Accumulator
  441.     moveq    #0,d0
  442. 1$    move.b    (a0)+,d0
  443.     beq.s    2$    ;Nothing there
  444.     cmpi.b    #' ',d0    ;Skip leading spaces
  445.     beq.s    1$
  446.     cmpi.b    #'0',d0    ;Check values
  447.     blt.s    2$
  448.     cmpi.b    #'9',d0
  449.     ble.s    3$
  450.  
  451. 2$    moveq    #-1,d0
  452.     bra.s    5$
  453.  
  454. 3$    add.l    d1,d1    ;Mult accumulated value *10
  455.     move.l    d1,-(sp)    ;*2
  456.     lsl.l    #2,d1    ;(*2) * (*4) = *8
  457.     add.l    (sp)+,d1    ;(*8) + (*2) = *10
  458.     andi.b    #$0F,d0    ;Mask hi-nibble
  459.     add.l    d0,d1    ;Add in new value
  460.  
  461.     move.b    (a0)+,d0    ;Get next char
  462.     beq.s    4$    ;Null ends
  463.     cmpi.b    #'0',d0    ;Check values
  464.     blt.s    4$    ;Non-number ends
  465.     cmpi.b    #'9',d0
  466.     ble.s    3$
  467. 4$    move.l    d1,d0
  468. 5$    subq.w    #1,a0    ;Wasn't ours, backup
  469.     movem.l    (sp)+,d1/a1
  470.     rts
  471.  
  472. ********************************************************************
  473. * NAME:     GenCmd()
  474. * FUNCTION: Setup SCSI bus for command phase & generate a class 00
  475. *           SCSI command.
  476. * INPUTS:   D1 = SCSI Device number
  477. *           A4 = NCR5380 base address
  478. * RETURN:   D0 = 0 if successful, or error code.
  479. * SCRATCH:  None
  480. ********************************************************************
  481.  
  482. GenCmd    move.l    #$40000,d0
  483. 1$    btst    #BCBS_BSY,ncr_bstat(a4)    ;Wait for free bus
  484.     beq.s    2$        ;If this doesn't happen after a
  485.     subq.l    #1,d0        ; while, exit (rather than hang).
  486.     bmi.s    4$
  487.     bpl.s    1$
  488. 2$    move.b    #PH_DOUT,ncr_tcmd(a4)    ;Setup 'Data Out' bus phase
  489.     moveq    #1,d0        ;Wait 1 bus settle delay
  490.     lsl.b    d1,d0        ;Shift device ID to a bit number
  491.     bset.b    #CLTD_HOST,d0        ;OR with ID of Host Controller
  492.     move.b    d0,ncr_data(a4)        ;Place ID on the data bus
  493.     nop            ;Wait 2 deskew delays
  494.     move.b    #ASS_BUS!ASS_SEL,ncr_icmd(a4) ;Assert select
  495.     move.l    #$40000,d0
  496. 3$    btst    #BCBS_BSY,ncr_bstat(a4)    ;Wait for target to respond
  497.     bne.s    5$        ; by asserting busy.
  498.     subq.l    #1,d0
  499.     bpl.s    3$        ;If this doesn't happen after a
  500. 4$    moveq    #0,d0        ; while, exit (rather than hang).
  501.     rts
  502.  
  503. 5$    nop            ;Wait 2 deskew delays
  504.     move.b    #ASS_NOT,ncr_icmd(a4)    ; and deassert select.
  505.     moveq    #1,d0
  506.     rts
  507.  
  508. *************************************************************************
  509. * NAME:     ScsiOutCmd()
  510. * FUNCTION: Send a class 00 command out the SCSI bus.
  511. * INPUTS:   A3 = Ptr to SCSICmd structure
  512. *           A4 = NCR5380 base address
  513. * RETURN:   None
  514. * SCRATCH:  None
  515. *************************************************************************
  516.  
  517. ScsiOutCmd    move.l    a3,-(sp)
  518.     tst.b    (a3)        ;If opcode 00 (Test Unit Ready),
  519.     beq.s    1$        ; go directly to Data Out phase.
  520.     move.b    #PH_CMD,ncr_tcmd(a4)    ;Else, setup 'Command' phase
  521.     bra.s    2$
  522. 1$    move.b    #PH_DOUT,ncr_tcmd(a4)    ;Setup 'Data Out' phase
  523.  
  524. 2$    move.b    #ASS_BUS,ncr_icmd(a4)    ;Assert the data bus
  525. 3$    btst    #BCBS_REQ,ncr_bstat(a4)    ;Wait for target to
  526.     beq.s    3$        ; assert Request.
  527.     btst    #PHAS_MATCH,ncr_stat(a4)    ;If we're not still in the
  528.     beq.s    5$        ; right phase, exit.
  529.     move.b    (a3)+,ncr_data(a4)    ;OK, send a byte of command
  530.     move.b    #ASS_BUS!ASS_ACK,ncr_icmd(a4) ;Send an ACK to target
  531. 4$    btst    #BCBS_REQ,ncr_bstat(a4)    ;Wait for target to
  532.     bne.s    4$        ; deassert Request.
  533.     move.b    #ASS_BUS,ncr_icmd(a4)    ;Reassert the data bus
  534.     bra.s    3$        ; and send the next byte.
  535.  
  536. 5$    move.b    #ASS_NOT,ncr_icmd(a4)    ;We got here because of a glitch
  537.     movea.l    (sp)+,a3        ; or we sent all the cmd bytes.
  538.     rts
  539.  
  540. *************************************************************************
  541. * NAME:     GetData()
  542. * FUNCTION: Do pseudo-DMA data transfer from SCSI bus.
  543. * INPUTS:   A2 = Data buffer.
  544. *           A4 = NCR5380 base address.
  545. * RETURN:   None
  546. * SCRATCH:  None
  547. *************************************************************************
  548.  
  549. GetData    move.l    a2,-(sp)
  550.     SYS    Disable
  551.     move.b    #PH_DIN,ncr_tcmd(a4)    ;Data In phase
  552. 1$    btst    #BCBS_REQ,ncr_bstat(a4)
  553.     beq.s    1$
  554.     btst    #PHAS_MATCH,ncr_stat(a4)
  555.     beq.s    11$
  556.  
  557.     move.b    #MONITOR_BSY,ncr_mode(a4)
  558.     move.b    #0,ncr_reset(a4)    ;Start DMA receive
  559.     move.b    #DMA_REQ,d1
  560.     lea    ncr_input(a4),a0
  561.     lea    ncr_stat(a4),a1
  562. 2$    btst    d1,(a1)
  563.     beq.s    3$
  564.     move.b    (a0),(a2)+
  565. 3$    btst    d1,(a1)
  566.     beq.s    4$
  567.     move.b    (a0),(a2)+
  568. 4$    btst    d1,(a1)
  569.     beq.s    5$
  570.     move.b    (a0),(a2)+
  571. 5$    btst    d1,(a1)
  572.     beq.s    6$
  573.     move.b    (a0),(a2)+
  574. 6$    btst    d1,(a1)
  575.     beq.s    7$
  576.     move.b    (a0),(a2)+
  577. 7$    btst    d1,(a1)
  578.     beq.s    8$
  579.     move.b    (a0),(a2)+
  580. 8$    btst    d1,(a1)
  581.     beq.s    9$
  582.     move.b    (a0),(a2)+
  583. 9$    btst    d1,(a1)
  584.     beq.s    10$
  585.     move.b    (a0),(a2)+
  586. 10$    btst    #INT_REQ,(a1)
  587.     beq.s    2$
  588.     move.b    #ARBITRATE,ncr_mode(a4)
  589.     tst.b    ncr_reset(a4)    ;Dummy read
  590. 11$    SYS    Enable
  591.     movea.l    (sp)+,a2
  592.     rts
  593.  
  594. *************************************************************************
  595. * NAME:     SCSIStat()
  596. * FUNCTION: Test the status of the SCSI bus.
  597. * INPUTS:   A4 = NCR5380 base address
  598. * RETURN:   D0 = Status
  599. * SCRATCH:  None
  600. *************************************************************************
  601.  
  602. SCSIStat    move.b    #PH_STAT,ncr_tcmd(a4)    ;Assert I/O and C/D
  603. 1$    btst    #BCBS_REQ,ncr_bstat(a4)    ;Wait for target to
  604.     beq.s    1$        ; assert Request.
  605.     moveq    #0,d0
  606.     move.b    ncr_data(a4),d0        ;Get status byte
  607.     move.b    #ASS_ACK,ncr_icmd(a4)    ;Send an ACK to target
  608. 2$    btst    #BCBS_REQ,ncr_bstat(a4)    ;Wait for target to
  609.     bne.s    2$        ; deassert Request.
  610.     move.b    #ASS_NOT,ncr_icmd(a4)    ;Drop bus
  611.     move.b    #PH_MIN,ncr_tcmd(a4)    ;Setup 'Message In' phase
  612. 3$    btst    #BCBS_REQ,ncr_bstat(a4)    ;Wait for target to
  613.     beq.s    3$        ; assert Request.
  614.     tst.b    ncr_data(a4)        ;Dummy read (expected)
  615.     move.b    #ASS_ACK,ncr_icmd(a4)    ;Send an ACK to target
  616. 4$    btst    #BCBS_REQ,ncr_bstat(a4)    ;Wait for target to
  617.     bne.s    4$        ; deassert Request.
  618.     move.b    #ASS_NOT,ncr_icmd(a4)    ;Drop bus
  619.     rts
  620.  
  621. *************************************************************************
  622. * NAME:     CheckAbort()
  623. * FUNCTION: Check for a ^C, and echo if found.
  624. * INPUTS:   None.
  625. * RETURN:   D0 = 1 if ^C, else 0.
  626. * SCRATCH:  D0-D1/A0-A1
  627. *************************************************************************
  628.  
  629. CheckAbort    move.l    a6,-(sp)
  630.     moveq    #0,d0
  631.     move.l    #$1000,d1
  632.     movea.l    SysBase,a6
  633.     SYS    SetSignal
  634.     andi.l    #$1000,d0
  635.     beq.s    1$
  636.     lea    BrkMsg(pc),a0
  637.     bsr.s    Puts
  638.     moveq    #1,d0
  639. 1$    movea.l    (sp)+,a6
  640.     rts
  641.  
  642. *********************************************************************
  643. * NAME:     Printf()
  644. * FUNCTION: Print formatted strings to stdout.
  645. * INPUTS:   A0 = Format string.
  646. *           A1 = Ptr to arguments.
  647. * RETURN:   None
  648. * SCRATCH:  D0-D1/A0-A1
  649. *********************************************************************
  650.  
  651. Printf    movem.l    a2-a3/a6,-(sp)
  652.     lea    KPutChar(pc),a2    ;Byte fill routine
  653.     lea    OutBuf(a5),a3
  654.     move.l    a3,-(sp)
  655.     movea.l    SysBase,a6
  656.     SYS    RawDoFmt    ;Do it!
  657.     movea.l    (sp)+,a0
  658.     bsr.s    Puts
  659.     movem.l    (sp)+,a2-a3/a6
  660.     rts
  661.  
  662. KPutChar    move.b    d0,(a3)+
  663.     rts
  664.  
  665. *************************************************************************
  666. * NAME:     Puts()
  667. * FUNCTION: Writes a message to stdout.
  668. * INPUTS:   A0 = Ptr to message.
  669. * RETURN:   None
  670. * SCRATCH:  D0-D1/A0-A1
  671. *************************************************************************
  672.  
  673. Puts    movem.l    d2-d4/a6,-(sp)
  674.     move.l    stdout(a5),d4
  675.     bsr.s    WriteMsg
  676.     movem.l    (sp)+,d2-d4/a6
  677.     rts
  678.  
  679. *************************************************************************
  680. * NAME:     WriteMsg()
  681. * FUNCTION: Common subroutine used by FPrintf, Printf, and Puts.
  682. * INPUTS:   A0 = Ptr to message.
  683. *           D4 = FileHandle.
  684. * RETURN:   None
  685. * SCRATCH:  D0-D1/A0-A1
  686. *************************************************************************
  687.  
  688. WriteMsg    move.l    a0,d3
  689. 1$    tst.b    (a0)+
  690.     bne.s    1$
  691.     exg    a0,d3
  692.     sub.l    a0,d3
  693.     subq.l    #1,d3    ;Length
  694.     move.l    a0,d2    ;Buffer
  695.     move.l    d4,d1    ;FileHandle
  696.     movea.l    DosBase(a5),a6
  697.     SYS    Write
  698.     rts
  699.  
  700. *************************************************************************
  701. * NAME:     ReportError()
  702. * FUNCTION: Sends the appropriate error message to stdout.
  703. * INPUTS:   Error = Offset from ErrStr.tbl.
  704. * RETURN:   None
  705. * SCRATCH:  D0-D1/A0-A1
  706. *************************************************************************
  707.  
  708. ReportError    move.w    Error(a5),d0
  709.     movea.l    ErrStr.tbl(pc,d0.w),a0
  710.     bra.s    Puts
  711.  
  712. ErrStr.tbl    dl    Usage.msg
  713.     dl    Error1.msg
  714.     dl    Error2.msg
  715.     dl    Error3.msg
  716.     dl    Error4.msg
  717.     dl    Error5.msg
  718.  
  719. Usage.msg    db    'Usage: 1> ReadErr <unit> [loBlk] [hiBlk]',10
  720.     db    'Where <unit> is a number from 0 to 15.',10
  721.     db    'Unit 0 corresponds to Device 1, logical unit 0.',10
  722.     db    'Unit 8 corresponds to Device 1, logical unit 1.',10
  723.     db    'Unit 1 corresponds to Device 2, logical unit 0.',10
  724.     db    'Unit 9 corresponds to Device 2, logical unit 1.',10
  725.     db    '(To address the 2nd logical device on an Adaptec',10
  726.     db    ' 4000 series, add 8 to the SCSI Device number.)',10
  727.     db    'Both loBlk and hiBlk are optional and refer to',10
  728.     db    'the starting and ending logical blocks.',10,0
  729. Error1.msg    db    'Unit number must be >= 0 and <= 15.',10,0
  730. Error2.msg    db    'Couldn''t open expansion.library.',10,0
  731. Error3.msg    db    '** NO CLtd Controller Found **',10,0
  732. Error4.msg    db    'Drive not responding.  Wrong unit number?',10,0
  733. Error5.msg    db    'Error reading capacity!!!',0
  734.  
  735. BannerStr    db    'Read Error and Translate V1.0 - ©1990 by Jeff Lavin',10,10,0
  736. Capacity.fmt    db    'Capacity of Device %d, LUN %d = %ld Sectors',10,10
  737.     db    'Working....',10,0
  738. ReadError.fmt    db    'Read Error at sector %d, Retrys %d',0
  739. CylHeadOffs.fmt    db    ', Cyl %ld, Head %d, Offset %ld',10,0
  740. Progress.fmt    db    'Block %ld',13,0
  741. Done.msg    db    10,'Done',10,10,0
  742. BrkMsg    db    10,10,'*** Break'
  743. NewLine    db    10,0
  744.  
  745. DosName    db    'dos.library',0
  746. ExpName    db    'expansion.library',0
  747.     cnop    0,4
  748.  
  749. DT    dx.b    Work_Sizeof
  750.  
  751.     end
  752.